import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

//静态路由配置
void main() => runApp(const MyApp3());

//定义根目录Widget
class MyApp3 extends StatelessWidget {
  const MyApp3({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      localizationsDelegates: const [
        //初始化默认的 Material 组件本地化
        GlobalMaterialLocalizations.delegate,
        //初始化默认的 通用 Widget 组件本地化
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      //当前区域，如果为null则使用系统区域一般用于语言切换
      //传入两个参数，语言代码，国家代码
      //这里配制为中国
      locale: const Locale('zh', 'CN'),
      //定义当前应用程序所支持的语言环境
      supportedLocales: const [
        Locale('en', 'US'), // English 英文
        Locale('zh', 'CN'), // 中文
      ],
      routes: {
        //默认页面
        "/": (BuildContext context) => const Exam214HomePage(),
      },
    );
  }
}


class Exam214HomePage extends StatefulWidget {
  const Exam214HomePage({Key? key}) : super(key: key);

  @override
  State<Exam214HomePage> createState() => _Exam214HomePageState();
}

class _Exam214HomePageState extends State<Exam214HomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //页面的头部
      appBar: AppBar(title: const Text("标题")),
      //页面的主内容区
      body: Center(child: Container(width: 224,child: buildRichText())),
    );
  }

  Widget buildRichText() {
    return  const TextField(
      //输入的字数最多为 11字
        maxLength: 11,
    )
    ;
  }
  ///代码清单2-19 TextField 输入限制
  ///代码路径 lib/code2/code214_TextField.dart
  Widget buildTextField4() {
    //表情内容
    const String REGEX_EMOJI =
        "[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]";
    return TextField(
      //设置键盘的类型
      keyboardType: TextInputType.phone,
      //输入文本格式过滤
      inputFormatters: [
        //输入的内容长度为11位
        LengthLimitingTextInputFormatter(11),
        //禁止表情输入
        FilteringTextInputFormatter.deny(RegExp(REGEX_EMOJI)),
        //只能输入数字限制
        FilteringTextInputFormatter.digitsOnly, //数字，只能是整数
        //只允许输入数字 正则
        FilteringTextInputFormatter.allow(RegExp("[0-9.]")), //数字包括小数
        FilteringTextInputFormatter.allow(RegExp("[a-zA-Z]")), //只允许输入字母
      ],
    );
  }

  ///设置无边框
  Widget buildTextField() {
    return  const TextField(
      //边框样式设置
      decoration: InputDecoration(
        //设置无边框
        border: InputBorder.none,
      ),
    );
  }

}
